<template>
	<div style="width: 100%;height: 100%">
		<el-row style="height: 10%;">
			<el-form class="search-form form-inline" label-width="120px" size="mini" ref="searchForm">
				<el-col :span="8">
					<el-form-item class="form-group" label="航班号：">
						<el-input v-model="searchForm.flightNo" placeholder="" clearable />
					</el-form-item>
				</el-col>
				<el-col v-if="auth == 0" :span="8">
					<el-form-item class="form-group" label="姓名：">
						<el-input v-model="searchForm.username" placeholder="" clearable />
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<el-row style="height: 10%;">
			<el-button type="primary" size="mini" plain class="el-icon-search" @click="doSearch(1)">查询</el-button>
			<!-- <el-button type="primary" size="mini" plain class="el-icon-edit" @click="doUpdate()">改签</el-button> -->
			<el-button v-if="auth == 1" type="primary" size="mini" plain class="el-icon-circle-close"
				@click="doUpdate()">退票</el-button>
		</el-row>
		<el-row style="height: 75%;">
			<el-table ref="table" :data="tableData" style="position: absolute" height="100%" size="mini"
				highlight-current-row border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="60" align="center" />
				<el-table-column prop="username" align="center" label="姓名" width="80" />
				<el-table-column prop="phone" align="center" label="电话号码" width="100" />
				<el-table-column prop="cardId" align="center" label="身份证号" :min-width="100" />
				<el-table-column prop="flightNo" align="center" label="航班号" width="200" />
				<el-table-column prop="startCity" align="center" label="始发城市" width="80" />
				<el-table-column prop="endCity" align="center" label="终点城市" width="80" />
				<el-table-column prop="startTime" align="center" label="始发时间" width="150" />
				<el-table-column prop="endTime" align="center" label="到达时间" width="150" />
				<el-table-column prop="price" align="center" label="支付金额" width="80" />
				<el-table-column prop="status" align="center" label="支付状态" width="80" />
			</el-table>
		</el-row>
		<el-row style="height: 5%;">
			<el-pagination :page-sizes="[30, 50, 100]" :current-page="searchForm.pageNo"
				:page-size="searchForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalCount"
				@size-change="handleSizeChange" @current-change="handleCurrentChange" />
		</el-row>
	</div>
</template>

<script>
	import axios from 'axios'

	export const uploadFileRequest = (url, body) => {
		return axios({
			method: 'post',
			url: url,
			data: body,
			responseType: 'blob'
		})
	}
	export default {
		props: {
			auth: {
				type: String
			},
			username: {
				type: String
			},
		},
		data() {
			return {
				searchForm: {
					flightNo: '',
					username: '',
					pageNo: 1,
					pageSize: 30
				},
				sexEnum: [{
					value: '女',
					label: '女'
				}, {
					value: '男',
					label: '男'
				}],
				tableData: [],
				totalCount: 0,
				dialogVisible: false,
				selection: []
			}
		},
		methods: {
			doSearch(pageNo) {
				this.searchForm.pageNo = pageNo
				console.log(this.auth)
				if (this.auth == '1') {
					this.searchForm.username = this.username
				}
				this.$axios.post("http://localhost:8888/order/getPage?pageNum=" + this.searchForm.pageNo +
						"&pageSize=" + this.searchForm.pageSize, this.searchForm)
					.then((data) => {
						console.log(data)
						this.tableData = data.data.records
						this.totalCount = data.data.total
					})
			},
			handleSizeChange(val) {
				this.searchForm.pageSize = val
				this.doSearch(1)
			},
			handleCurrentChange(val) {
				this.doSearch(val)
			},
			handleSelectionChange(selection) {
				this.selection = selection
			},
			doUpdate() {
				console.log(this.selection[0].status)
				if (this.selection[0].status === '已退票') {
					this.$message.warning('该订单无法退票');
					return;
				}
				if (this.selection.length == 1) {
					this.$axios.post("http://localhost:8888/order/refundTicket", this.selection[0]).then((data) => {
						if (data.data == 1) {
							this.$message.success("退票成功")
							this.doSearch(1)
						}
					})
				} else if (this.selection.length == 0) {
					this.$message.warning('请选择一条信息进行修改');
				} else {
					this.$message.warning('只能选择一条信息进行修改');
				}
			}
		},
		mounted() {
			this.doSearch(1)
		}
	}
</script>

<style scoped>
</style>
